package model

import "sync"

// PointItem 数据点位信息
type PointItem struct {
	Module   uint8   `json:"module"`
	Title    string  `json:"title"`
	Addr     string  `json:"addr"`
	Value    float64 `json:"value"`
	DataType string  `json:"data_type"`
	//CreateTime *string `json:"create_time" gorm:"column:create_time"`
}

type Alert struct {
	ID           int     `json:"id" gorm:"column:id"`
	Module       uint8   `json:"module" gorm:"column:module"`
	Title        string  `json:"title" gorm:"column:title"`
	Addr         string  `json:"addr" gorm:"column:addr"`
	Value        float64 `json:"value" gorm:"column:value"`
	CreateTime   *string `json:"create_time" gorm:"column:create_time"`
	IsRecovery   uint8   `json:"is_recovery" gorm:"column:is_recovery"`
	RecoveryTime *string `json:"recovery_time" gorm:"column:recovery_time"`
}

func (t *Alert) TableName() string {
	return "alert"
}

type AlertDataMapStu struct {
	M map[string]*Alert
	sync.RWMutex
}

func NewAlertDataMap() *AlertDataMapStu {
	return &AlertDataMapStu{
		M: make(map[string]*Alert),
	}
}
func (m *AlertDataMapStu) Set(key string, v *Alert) {
	m.Lock()
	defer m.Unlock()
	m.M[key] = v
}
func (m *AlertDataMapStu) Get(key string) (v *Alert, ok bool) {
	m.RLock()
	defer m.RUnlock()
	v, ok = m.M[key]
	if !ok {
		v = &Alert{}
	}
	return
}
func (m *AlertDataMapStu) Delete(key string) {
	m.Lock()
	defer m.Unlock()
	delete(m.M, key)
}
